package day06;

import java.io.File;

public class Demo14 {

	public static void main(String[] args) throws Exception {

		File dir = new File("test");
		
		Long ll =FileLength(dir);
		System.out.println(ll);

	}

	public static Long FileLength(File dir) {

		if (!dir.exists()) {
			return 0L;
		}

		if (dir.isFile()) {
			return dir.length();
		}

		long sum = 0L;
		File[] files = dir.listFiles();

		for (File f : files) {
			if (f.isDirectory()) {
				long num = FileLength(f);
				sum += num;
			} else {
				sum += f.length();
			}

		}
		return sum;

	}

}
